home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1999 July / Macworld (1999-07).dmg / Serious Software / OpenWorld demo 2.0 / Development / SingleTag / Modification Date / ModDate.c next >
Text File  |  1999-04-27  |  2KB  |  84 lines

  1. /*  File: ModDate.c      
  2.     Copyright (c) 1999 Marco Bambini. All rights reserved.
  3.  
  4.     Description: return the modification date of the file
  5. */
  6.  
  7. #include "OpenWorld_plugIn.h"
  8. #include "OpenWorld_utils.h"
  9. #include <CodeFragments.h>
  10. #include <Files.h>
  11. #include <Packages.h>
  12.  
  13. long GetFileModDate(FSSpec *spec,short fRef);
  14.  
  15. Boolean main (dataPtr param)
  16. {    
  17.     switch (param->message)
  18.     {    
  19.         case init_message:
  20.             {
  21.                 param->version=kVersion;
  22.                 param->customData=kUnused;
  23.             }
  24.             break;
  25.             
  26.         case run_message:
  27.             {                    
  28.                 long         date;
  29.                 Str255        resultStr;
  30.                 long        dim;
  31.                 
  32.                 // get the file modification date
  33.                 date=GetFileModDate(&(param->myFile),param->fRef);
  34.                 if (date==-1) return NULL;
  35.                 
  36.                 if (up_strcmp(param->search,"SHORT")==NULL) IUDateString(date,shortDate,resultStr);    // short date: 10/1/98
  37.                 else
  38.                 if (up_strcmp(param->search,"LONG")==NULL) IUDateString(date,longDate,resultStr);    // long date: Monday, February 1, 1998
  39.                 else
  40.                 if (up_strcmp(param->search,"ABBR")==NULL) IUDateString(date,abbrevDate,resultStr);    // abbrev. date: Mon, Feb 1, 1998
  41.                 else
  42.                 IUDateString(date,shortDate,resultStr);    //default
  43.                 
  44.                 // get the size of the string
  45.                 dim=resultStr[0];
  46.                 
  47.                 // convert the result into an HTML string
  48.                 param->outputText=OW_TextToHTML(param,&resultStr[1],&dim);
  49.  
  50.                 if (param->outputText) param->dim=dim;
  51.             }
  52.             break;
  53.         
  54.         case stop_message:
  55.             {
  56.                 // dispose the buffer
  57.                 OW_DisposePtr(param,param->outputText);
  58.             }
  59.             break;
  60.         
  61.         case end_message:
  62.             {
  63.                 // do nothing
  64.             }
  65.             break;
  66.     }
  67.     return kSingleTag;
  68. }
  69.  
  70. long GetFileModDate(FSSpec *spec,short fRef)
  71. {
  72.     CInfoPBRec     pb;
  73.     OSErr        err;
  74.     
  75.     pb.hFileInfo.ioFDirIndex = 0;
  76.     pb.hFileInfo.ioNamePtr = spec->name;
  77.     pb.hFileInfo.ioVRefNum = spec->vRefNum;
  78.     pb.hFileInfo.ioFRefNum = fRef;
  79.     pb.hFileInfo.ioDirID = spec->parID;
  80.     
  81.     err=PBGetCatInfoSync(&pb);
  82.     if (err==noErr) return (pb.hFileInfo.ioFlMdDat);
  83.     else return -1;
  84. }